package io.renren.modules.demo.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.renren.common.entity.XlsCirclePriEntity;
import io.renren.common.entity.XlsUserAwardEntity;
import io.renren.common.enums.CircleLevelEnum;
import io.renren.common.page.PageData;
import io.renren.common.service.impl.CrudServiceImpl;
import io.renren.modules.demo.dao.XlsUserAwardDao;
import io.renren.modules.demo.dto.XlsCirclePriDTO;
import io.renren.modules.demo.dto.XlsUserAwardDTO;
import io.renren.modules.demo.service.XlsUserAwardService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * 用户奖励表
 *
 * @author Mark sunlightcs@gmail.com
 * @since 1.0.0 2020-04-16
 */
@Service
public class XlsUserAwardServiceImpl extends CrudServiceImpl<XlsUserAwardDao, XlsUserAwardEntity, XlsUserAwardDTO> implements XlsUserAwardService {

    @Override
    public QueryWrapper<XlsUserAwardEntity> getWrapper(Map<String, Object> params) {

        QueryWrapper<XlsUserAwardEntity> wrapper = new QueryWrapper<>();

        return wrapper;
    }

    @Override
    public PageData<XlsUserAwardDTO> queryPage(Map<String, Object> params) {
        QueryWrapper<XlsUserAwardEntity> wrapper = getWrapper(params);
        wrapper.le("xu.circle_level", CircleLevelEnum.PARTNER_LEVEL.value());
        wrapper.ge("xu.circle_level", CircleLevelEnum.PRIMARY_LEVEL.value());
        if(ObjectUtil.isNotEmpty(params.get("mobile"))) {
            wrapper.eq("xu.mobile", params.get("mobile"));
        }
        if(ObjectUtil.isNotEmpty(params.get("username"))) {
            wrapper.like("xu.username", params.get("username"));
        }
        IPage<XlsUserAwardDTO> page = baseDao.queryPage(
                getPage(params, null, false),
                wrapper
        );

        return getPageData(page, currentDtoClass());
    }


}